import request from '@/utils/request.js'
import { CONFIG } from '@/config/app'

// 上传文件
export async function uploadFile(tempFilePaths = []) {
  console.log('#######################', tempFilePaths)
  return new Promise((resolve, reject) => {
    tempFilePaths.forEach(item => {
      uni.uploadFile({
        url: CONFIG.HTTP_REQUEST_URL + 'app-api/infra/file/upload',
        header: {
          token: uni.getStorageSync('token'),
        },
        filePath: item,
        name: 'file',
        success: uploadFileRes => {
          uploadFileRes = JSON.parse(uploadFileRes.data)
          console.log('=== uploadFileRes ==========================', uploadFileRes)
          if (uploadFileRes.code == 0) {
            resolve(uploadFileRes.data)
          } else {
            uni.showToast({
              title: uploadFileRes.msg,
              icon: 'none',
              duration: 2000,
            })
          }
        },
        fail: error => {
          uni.showToast('上传失败，请联系开发！')
          reject(error)
        },
      })
    })
  })
}

// 创建会话记录
export function createSessionRecord(data) {
  return request.post(`app-api/dybz/member-message/createSessionRecord`, data)
}

// 创建聊天记录
export function createMemberMessage(data) {
  return request.post(`app-api/dybz/member-message/createMemberMessage`, data)
}
// 获取聊天记录
export function getMemberMessagePage(data) {
  return request.get(`app-api/dybz/member-message/getMemberMessagePage`, data)
}

// 发送群系统通知
export function sendSystemNotification(data) {
  return request.post(`app-api/dybz/member-message/sendNotification`, data)
}

// 发送群普通消息
export function sendGroupMessage(groupId, message) {
  const groupMessage = {
    groupId,
    msgBody: JSON.stringify([
      {
        MsgType: 'TIMCustomElem',
        MsgContent: {
          Data: JSON.stringify(message),
        },
      },
    ]),
  }
  return request.post(`app-api/dybz/member-message/sendGroupMessage`, groupMessage)
}

// 发送群消息
// const message = {
//   businessID: 'card',
//   title: '会诊服务',
//   text: '医生已为您推荐了会诊服务的医生，点击即可缴费会诊服务的医生，会诊服务的医生，会诊服务的.......',
//   buttonText: '去查看',
//   buttonUrl: '/pages/ConsultationRoom/Prescription/Prescription',
// }

// const message = {
//   businessID: 'top_tip',
//   content: '医生已接诊，交流通道已开启，最长交流时长为48小时，请医患及时进行问诊',
// }

// 发送群消息
// sendGroupMessage('@TGS#1AWTSXQOX', message)

// 消息类型
export const MessageTpye = {
  consultation: {
    businessID: 'tip',
    type: 'card',
    icon: '',
    title: '会诊服务',
    text: '医生已为您推荐了会诊服务的医生，点击即可缴费会诊服务的医生，会诊服务的医生，会诊服务的.......',
    buttonText: '去查看',
    buttonUrl: '/pages/ConsultationRoom/Prescription/Prescription',
  },
  prescription: {
    businessID: 'tip',
    type: 'card',
    icon: '',
    title: '处方笺',
    text: '医生已为您推荐了会诊服务的医生，点击即可缴费会诊服务的医生，会诊服务的医生，会诊服务的.......',
    buttonText: '去查看',
    buttonUrl: '/pages/ConsultationRoom/PrescriptionDetails/PrescriptionDetails',
  },
  prescription: {
    businessID: 'tip',
    type: 'card',
    icon: '',
    title: '视频通话录像',
    text: '于2024.5.21 13:00开始至2024.05.21 13:10结束共计视频通话时长10分钟',
    buttonText: '查看录像',
    buttonUrl: '/pages/ConsultationRoom/Prescription/Prescription',
  },
  prescription: {
    businessID: 'tip',
    type: 'card',
    icon: '',
    title: '设置视频时间',
    text: '为保证视频问诊的顺畅，请医生提前设置视频时间以告知用户',
    buttonText: '去设置时间',
    buttonUrl: '/pages/ConsultationRoom/Prescription/Prescription',
  },
  prescription: {
    businessID: 'tip',
    type: 'card',
    icon: '',
    title: '问诊建议',
    text: '初步诊断是确定疼痛症状原因的关键步骤。通过疼痛问诊的要点详细的询问疼痛特征、了解个人病史......',
    buttonText: '去查看',
    buttonUrl: '/pages/ConsultationRoom/proposal/proposal',
  },
}
